\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28 single pixel read\
\
Q: I want to read some specific pixel values from a window. How do I do that? \
\
\fi-440\li440 A: Here's the code for the function
\b colorAt
\b0 () which will return the color of a pixel in an instance of NXBitmapImageRep. If you want to read the pixel off of a window, you would first lock the focus in an appropriate view of the window, then use:\
\fi0\li0 \
\pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\f2\fs24\fc0 NXRect rect = \{\{0.0, 0.0\}, \{4.0, 4.0\}\};\
id image = [[NXBitmapImageRep alloc] initData:NULL fromRect:&rect];\
\pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\fc0 Here rect is the rectangle for which you want to get the pixels from the window server to the app. Of course, if all you need to do is read one pixel from a window, then set rect to \{\{x, y\}, \{1, 1\}\} and look at the color at location 0, 0.\
\
You can do the same thing for an NXImage: lock focus on it and using the above method read a pixel. Or, better yet, if you want to read pixels from a TIFF file you can directly use the NXBitmapImageRep without having to read pixels back from the window server.\
\
Here's the routine. If it is too complicated or too slow (which it might end up being, if you want to run in a loop over zillions of pixels), you can remove some of the fluff code like conversion of raw data value to an NXColor() and even alpha computation... \